<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>process-rule-excluderes</title>
	 <%@ include file="../include/common.jsp"%>
	 <%@ include file="../include/tree.jsp"%>
    <%@ include file="../include/form.jsp"%>
    <%@ include file="../include/jbox.jsp"%>
	<style type="text/css">
		.ztree {border: 1px solid #617775;background: #f0f6e4;width:220px;height:360px;overflow-y:scroll;overflow-x:auto;}
	</style>
	<link rel="stylesheet" media="all" type="text/css" href="${pageContext.request.contextPath}/style/default/tree/demo.css" />
	<script type="text/javascript">
		
	  function add(){
		  	if($("#resId").val() == ''){
		  		 getTopWin(window).getMessageBox().alert("请勾选资源","提示");
		  		return false;
		  	}
				  $.ajax({
					   type: "POST", 
					   url: "${pageContext.request.contextPath}/order/process-rule!saveResExclude.action", 
					   data: $("#myform").serialize(), //传的参数
					   dataType: 'json',
					   success: function(data){ //结果
							   var pWin = getTopWin(window).currentWin["add-exclude-rule"];
							   pWin.datagridResExclude();
							   getTopWin(window).closejBox("add-exclude-rule");
					   }
				});
	  }
	$(function(){
		showResTree();
		$.formValidator.initConfig({formid:"myform"
	          ,onerror:function(msg){}
	          ,onsuccess:function(){
	        	  		add();
	          			return false;
	          }
	    });
	})
	function closewin(){
	  getTopWin(window).closejBox("add-exclude-rule");
  }
 
	  var setting = {
			  async: {
					enable: true,
					url:"${pageContext.request.contextPath}/resource/res-frame!customizeTree.action?startId="+${resId},
					dataType: "text",
					autoParam:["id"]
				},
				check: {
					enable: true,
					chkboxType: {"Y" : "s", "N" : "s"}
				},
				view: {
					dblClickExpand: false
				},
				data: {
					simpleData: {
						enable: true
					}
				},
				callback: {
					onCheck: onCheck
				}
			};
			function onCheck(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
				nodes = zTree.getCheckedNodes(true),
				v = "";
				m = "";
				for (var i=0, l=nodes.length; i<l; i++) {
					if(nodes[i].id.substring(0,1) == 2){
							//根节点不显示
							if(nodes[i].id != -1){
								v += nodes[i].name + ",";
							}
							m += nodes[i].id.split('|')[1] + ",";
					}
				}
				if (v.length > 0 ) v = v.substring(0, v.length-1);
				if (m.length > 0 ) m = m.substring(0, m.length-1);
				$("#resName").val(v);
				$("#resId").val(m);
			}
			function showResTree() {
				$.ajax({ 
					  type:"post", 
					  url:"${pageContext.request.contextPath}/resource/res-frame!customizeTree.action?startId="+${resId}, 
					  data:"", 
					  datatype:"json",
					  success:function(data) { 
							var zNodes=eval(data);
							$.fn.zTree.init($("#treeDemo"), setting, zNodes);
					  } 
			     	})
			}
			
	</script>
  </head>
  
  <body class="padding-8">
  		<form action="" id="myform" name="myform" method="post">
    		<div align="left" style="margin-bottom: 5px">
	    		<input type="submit" id="button" name="button" value="保存" class="btn-4">
	    		<input type="button" value="取消" onclick="closewin();" class="btn-4">
    		</div>
    		<input type="hidden" id="workOrderId" name="workOrderId" value=${workOrderId}>
    		<input id="resId" name="resId" type="hidden">
    	</form>
		<ul id="treeDemo" class="ztree" style="margin-top:0; width:312px; height: 268px;"></ul>
  </body>
</html>
